﻿using MongoDB.Driver;
using Sustainalytics.ESG.Entities;
using Sustainalytics.Synchronization.Validation.Handlers.Common;
using Sustainalytics.Synchronization.Validation.Internals;
using Sustainalytics.Synchronization.Validation.Validators;
using System;

namespace Sustainalytics.Synchronization.Validation.Handlers.Core
{
    internal class CoreCompanyComputationResultHandler : Handler<RPCompanyESGComputationResult, CoreCompanies>
    {
        public CoreCompanyComputationResultHandler(CoreCompanies comprehensiveCompanies, ValidationMongoCollection<RPCompanyESGComputationResult> collections, CoreValidator<RPCompanyESGComputationResult> validator)
            : base(comprehensiveCompanies, collections, validator)
        {
        }

        protected override ProjectionDefinition<RPCompanyESGComputationResult> GetProjectionDefinition()
        {
            return
                Builders<RPCompanyESGComputationResult>.Projection.Include(x => x.Id)
                    .Include(x => x.Indicators)
                    .Include(x => x.OverallPerformance);
        }

        protected override FilterDefinition<RPCompanyESGComputationResult> GetReferenceEntityFilter(RPCompanyESGComputationResult validatedEntity)
        {
            return Builders<RPCompanyESGComputationResult>.Filter.Where(x => x.Id == validatedEntity.Id);
        }

        protected override FilterDefinition<RPCompanyESGComputationResult> GetValidatedEntityFilterDefinition(Guid companyId)
        {
            return Builders<RPCompanyESGComputationResult>.Filter.Where(x => x.Id == companyId);
        }
    }
}
